package com.esxy.cloud.controller;

import com.esxy.cloud.pojo.Payment;
import com.esxy.cloud.service.PaymentService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//controller调service,service调mapper,在xml文件中写sql语句
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @GetMapping("/getPaymentAll")
    public List<Payment> getPaymentAll() {
        List<Payment> paymentList = paymentService.getPayment();
        return paymentList;
    }

//    @RequestMapping("/getInsertPayment")
//    public void getInsertPayment() {
//        int num = paymentService.InsertPayment(58, "fwp");
//        if (num>0){
//            System.out.println("新增成功");
//        }else {
//            System.out.println("新增失败");
//        }
//    }

        @PostMapping("/getInsertPayment")
    public void getInsertPayment2(Payment payment) {
        int num1 = paymentService.InsertPayment(payment);
        if (num1>0){
            System.out.println("新增成功");
        }else {
            System.out.println("新增失败");
        }
    }

    @PostMapping("/getUpdatePayment")
    public void getUpdatePayment(Payment payment) {
        int num2 = paymentService.UpdatePayment(payment);
        if(num2>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
    }

    @DeleteMapping("/getDeletePayment")
    public void getDeletePayment(Integer id) {
        int number = paymentService.DeletePayment(55);
        if (number>0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
